﻿/*************************************************************************
*
*	main.cpp -- Application entry point
*
*		-by Miles Chen (stainboyx@hotmail.com)
*
*************************************************************************/
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")



#include <Windows.h>
#include <CommCtrl.h>
#pragma comment (lib, "Comctl32.lib")

#include "resource.h"

#define IDM_ABOUT	20001
#define ERR_CHANGE_LOCALE 1050
#define ERR_EXIT 1000


INT_PTR CALLBACK DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_INITDIALOG:
		{
			//
			HICON hIcon = LoadIconW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDI_APP));
			SendMessageW(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
			SendMessageW(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
			//
			HMENU hMenu = GetSystemMenu(hDlg, FALSE);
			AppendMenuW(hMenu, MF_ENABLED | MF_STRING, IDM_ABOUT, L"&About");
			//
			return TRUE;
		}
		break;
	case WM_SYSCOMMAND:
		{
			//
			switch(wParam)
			{
			case IDM_ABOUT:
				{
					HICON hIcon = LoadIconW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDI_APP));
					ShellAboutW(hDlg, L"飞鸟影视", L"stainboyx@hotmail.com", hIcon);
				}
				break;
			}
		}
		break;
	case WM_COMMAND:
		{
			//
			switch(wParam)
			{
			case IDC_UPDATE:
				{
					// Vista or 7
					LANGID newLang = (GetThreadUILanguage() == 1033 ? 2052 : 1033);
					SetThreadUILanguage(newLang);

					// Xp
					//LCID newLang = (GetThreadLocale() == 1033 ? 2052 : 1033);
					//SetThreadLocale(newLang);

					EndDialog(hDlg, ERR_CHANGE_LOCALE);
					return TRUE;
				}
				break;
			}
		}
		break;
	case WM_CLOSE:
		{
			EndDialog(hDlg, ERR_EXIT);
			return TRUE;
		}
		break;
	}
	return FALSE;
}


int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpstrCmdLine, int nCmdShow)
{
	InitCommonControls();
	while(ERR_CHANGE_LOCALE == DialogBoxParamW(hInstance, MAKEINTRESOURCEW(IDD_WINDOW), NULL, DialogProc, NULL))
		;
	return 0;
}